#!usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime

from ._base import BaseModel, db


class Area(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(200))
    pid = db.Column(db.Integer)
    s_name = db.Column(db.String(200))
    level = db.Column(db.Integer)
    city_code = db.Column(db.String(20))
    yz_code = db.Column(db.String(20))
    name_path = db.Column(db.String(300))
    id_path = db.Column(db.String(30))
    lng = db.Column(db.DECIMAL(12, 6))
    lat = db.Column(db.DECIMAL(12, 6))
    pin_yin = db.Column(db.String(300))
    sort = db.Column(db.Integer, default=0)
    is_discard = db.Column(db.SmallInteger, comment=u'1废弃')

    dict_default_columns = ["id", "name", "pid", "s_name", "level", "city_code", "yz_code",
                            "name_path", "id_path", "lng", "lat", "pin_yin", "sort"]


"""
数据来源平台
"""
class Platform(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(200), comment=u'平台名称')
    dict_default_columns = ["id", "name", "sys_type", "package", "launcher"]


"""
平台账号管理
"""
class PlatformAccount(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    platform_id = db.Column(db.Integer, comment=u'数据来源平台')
    account = db.Column(db.String(200), comment=u'登录账号')
    password = db.Column(db.String(200), comment=u'登录密码')
    status = db.Column(db.SmallInteger, comment=u'状态 1:正常  2:关闭')


"""
设备管理
"""
class Device(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    platform_id = db.Column(db.Integer, comment=u'数据来源平台')
    sys_type = db.Column(db.SmallInteger, comment=u'系统类型 1：android  2：ios')
    package = db.Column(db.String(200), comment=u'平台app包名')
    launcher = db.Column(db.String(200), comment=u'平台app启动activity')
    name = db.Column(db.String(200), comment=u'设备名称')
    udid = db.Column(db.String(200), comment=u'设备adb通道编码')
    appium_service_id = db.Column(db.Integer, comment=u'连接哪个appimn服务')
    status = db.Column(db.SmallInteger, comment=u'服务状态1:运行中中 2:关闭  3：异常')
    source_type = db.Column(db.SmallInteger, comment=u'执行方式 1：搜索  2：关注')
    is_use = db.Column(db.SmallInteger, comment=u'是否可用 1：是 2：否')


"""
appium服务管理
"""
class AppiumService(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    port = db.Column(db.String(10), comment=u'启动端口')
    start_time = db.Column(db.DateTime, comment=u'最后一次启动时间')
    close_time = db.Column(db.DateTime, comment=u'最后一次关闭时间')
    except_time = db.Column(db.DateTime, comment=u'最后一次异常时间')
    status = db.Column(db.SmallInteger, comment=u'服务状态1:服务中 2:关闭  3：异常')